import Vue from 'vue'
import Router from 'vue-router'

import Upload from '@/components/Upload'
import Manage from '@/components/Manage'
import Main from '@/components/Main'
import Version from '@/components/Versions'
import addVersion from '@/components/AddVersion'
import Updates from '@/components/Updates'

import Test from '@/components/Test'

Vue.use(Router)

const router = new Router({
  routes: [{
      path: '/',
      name: 'main',
      component: Main,
      meta: {
        title: '首页'
      }
    }, {
      path: '/upload',
      name: 'upload',
      component: Upload,
      meta: {
        title: '差分'
      }
    },
    {
      path: '/manage',
      name: 'manage',
      component: Manage,
      meta: {
        title: '差分'
      }
    },
    {
      path: '/versions',
      name: 'versions',
      component: Version,
      meta: {
        title: '版本管理'
      }
    },
    {
      path: '/version/:appType',
      name: 'version',
      component: Version,
      meta: {
        title: '版本管理'
      }
    },
    {
      path: '/addVersion',
      name: 'addVersion',
      component: addVersion,
      meta: {
        title: '添加版本'
      }
    },
    {
      path: '/updates/:appType',
      name: 'updates',
      component: Updates,
      meta: {
        title: '更新管理'
      }
    },
    {
      path: '/test',
      name: 'test',
      component: Test,
      meta: {
        title: '差分'
      }
    }
  ]
})

router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router
